Skip to content

feat: adds explicit AND, OR, NOT filters#959

Merged
micheleriva merged 1 commit into
mainfrom
feat/adds-explicit-filters
Jul 12, 2025
Merged

feat: adds explicit AND, OR, NOT filters#959
micheleriva merged 1 commit into
mainfrom
feat/adds-explicit-filters

Conversation

@micheleriva

@micheleriva micheleriva commented Jul 12, 2025

Copy link
Copy Markdown
Contributor

Logical Operators

With Orama you can combine multiple filters using logical operators like and, or, and not.

  • and: this operator accepts an array of filters. All conditions must be true.
  • or: this operator accepts an array of filters. At least one condition must be true.
  • not: this operator accepts a single filter. The condition must be false.

All operators can be nested.

Examples

This filter will return all documents that have the category "electronics":

const results = search(db, {
  term: "phone",
  where: {
    category: "electronics"
  }
})

This filter will return all documents that have the category "electronics" and the price less than 100:

const results = search(db, {
  term: "phone",
  where: {
    category: "electronics",
    price: { lt: 100 }
  }
})

With the above filters, you can only filter applying and operator implicitly. You can also use the and operator explicitly:

const results = search(db, {
  term: "phone",
  where: {
    and: [
      { category: "electronics" },
      { price: { lt: 100 } }
    ]
  }
})

This filter will return all documents that have:

  • (category = "electronics") OR (price < 100).
const results = search(db, {
  term: "phone",
  where: {
    or: [
      { category: "electronics" },
      { price: { lt: 100 } }
    ]
  }
})

This filter will return all documents that have:

  • (price < 100) AND NOT (category = "electronics").
const results = search(db, {
  term: "phone",
  where: {
    and: [
      { price: { lt: 100 } },
      { not: { category: "electronics" } }
    ]
  }
})

This filter will return all documents that have:

  • ( (category = "electronics") AND (price < 100) ) OR ( NOT (category = "electronics") AND (price < 100) )
const results = search(db, {
  term: "phone",
  where: {
    or: [
      {
        and: [
          { category: "electronics" },
          { price: { lt: 100 } }
        ]
      },
      {
        and: [
          { not: { category: "electronics" } },
          { price: { lt: 100 } }
        ]
      }
    ]
  }
})

@vercel

vercel Bot commented Jul 12, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orama-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2025 8:34pm

@micheleriva micheleriva merged commit 33ebadf into main Jul 12, 2025
3 checks passed
@micheleriva micheleriva deleted the feat/adds-explicit-filters branch July 12, 2025 20:40
@micheleriva micheleriva mentioned this pull request Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant